package com.example.smartcitydemo.ui.subway

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.recyclerview.widget.RecyclerView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseDataBindingHolder
import com.example.smartcitydemo.R
import com.example.smartcitydemo.bean.*
import com.example.smartcitydemo.databinding.*
import com.example.smartcitydemo.ext.addMaterialButton
import com.example.smartcitydemo.ui.subway.bean.SubWayServiceBean
import com.example.smartcitydemo.ui.subway.bean.WeatherBannerBean
import com.youth.banner.adapter.BannerAdapter

/**
 * @PACKAGE_NAME: com.example.smartcitydemo.ui.subway
 * @NAME: Caleb.F
 * @DATE: 2021/11/15 10:33
 * @Email: 1919796283@qq.com
 */
class WeatherBannerAdapter(val list: List<WeatherBannerBean>) :
    BannerAdapter<WeatherBannerBean, MyViewHolder>(list) {
    override fun onCreateHolder(parent: ViewGroup, viewType: Int): MyViewHolder {
        val inflate = LayoutInflater.from(parent.context)
            .inflate(R.layout.subway_weather_banner, parent, false)
        return MyViewHolder(inflate)
    }

    override fun onBindView(
        holder: MyViewHolder,
        data: WeatherBannerBean?,
        position: Int,
        size: Int
    ) {
        val bind = DataBindingUtil.bind<SubwayWeatherBannerBinding>(holder.itemView)
        bind?.run {
            data?.let {
                tvTitle.text = it.bannerTitle
                tvWeatherFirst.text = it.bannerFirstString
                tvWeatherSecond.text = it.bannerSecondString
            }
        }
    }
}


class MyViewHolder(val view: View) : RecyclerView.ViewHolder(view)


val serviceList = mutableListOf(
    SubWayServiceBean(R.drawable.subway_first, "站点查询"),
    SubWayServiceBean(R.drawable.subway_second, "线路查询"),
    SubWayServiceBean(R.drawable.subway_third, "乘车须知"),
    SubWayServiceBean(R.drawable.subway_four, "运营公告")

)

class SubWayServiceAdapter :
    BaseQuickAdapter<SubWayServiceBean, BaseDataBindingHolder<RecyclerSubwayServiceBinding>>
        (R.layout.recycler_subway_service, serviceList) {
    override fun convert(
        holder: BaseDataBindingHolder<RecyclerSubwayServiceBinding>,
        item: SubWayServiceBean
    ) {
        holder.dataBinding?.let {
            it.imageView12.setImageResource(item.imageId)
            it.textView9.text = item.title
        }

    }
}


class LeftRecyclerAdapter :
    BaseQuickAdapter<LineDataBean, BaseDataBindingHolder<SubwayLeftRecyclerBinding>>(R.layout.subway_left_recycler) {
    override fun convert(
        holder: BaseDataBindingHolder<SubwayLeftRecyclerBinding>,
        item: LineDataBean
    ) {
        holder.dataBinding?.data = item
    }

}

class RightRecyclerAdapter :
    BaseQuickAdapter<StationDataBean, BaseDataBindingHolder<SubwayRightRecyclerBinding>>(
        R.layout.subway_right_recycler
    ) {
    override fun convert(
        holder: BaseDataBindingHolder<SubwayRightRecyclerBinding>,
        item: StationDataBean
    ) {
        holder.dataBinding?.run {
            tvSubwayStationInfo.text = item.name
            //清除所有的view
            subwayChildLayout.removeAllViews()
            subwayChildLayout.addMaterialButton(item.distinctList)
        }
    }



}
class SubWayDetailAdapter :
    BaseQuickAdapter<LineDetail, BaseDataBindingHolder<RvSubDetailBinding>>(
        R.layout.rv_sub_detail
    ) {
    override fun convert(holder: BaseDataBindingHolder<RvSubDetailBinding>, item: LineDetail) {
        holder.dataBinding?.data = item
    }
}

class SubWayNoticeAdapter :
        BaseQuickAdapter<SubWayNoticeBean, BaseDataBindingHolder<RvSubwayNotificationBinding>>(R.layout.rv_subway_notification) {
        override fun convert(
            holder: BaseDataBindingHolder<RvSubwayNotificationBinding>,
            item: SubWayNoticeBean
        ) {
            holder.dataBinding?.data = item
        }

}

class SubWayHomeAdapter:BaseQuickAdapter<CurrentStationDetail,BaseDataBindingHolder<RecyclerHomeItemBinding>>(R.layout.recycler_home_item) {
    override fun convert(
        holder: BaseDataBindingHolder<RecyclerHomeItemBinding>,
        item: CurrentStationDetail
    ) {
        holder.dataBinding?.data =item
        holder.dataBinding?.tvCurrentGroup?.addMaterialButton(listOf(Line(0,lineName = item.lineName)))
        holder.dataBinding?.tvCurrentGroup?.addMaterialButton(listOf(Line(0,lineName = item.lineName)))
        holder.dataBinding?.tvStartGroup?.addMaterialButton(item.preStep.distinctList)
        holder.dataBinding?.tvEndGroup?.addMaterialButton(item.nextStep.distinctList)

    }
}